package com.future.lock.common.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.Window;

import com.future.baselib.utils.UserInfoSharePreference;
import com.future.lock.R;
import com.future.lock.common.MyApp;

import java.util.Timer;
import java.util.TimerTask;


public class StartActivity extends AppCompatActivity {

    private Timer timer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        MyApp.setUserToken(UserInfoSharePreference.getInstance(this).getUserToken());
    }

    @Override
    protected void onResume() {
        super.onResume();
        timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(() -> {
                    startActivity(new Intent(StartActivity.this,MainActivity.class));
                    finish();
                });
            }
        },2000);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (KeyEvent.KEYCODE_BACK == keyCode) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onStop() {
        super.onStop();
        timer.cancel();
    }
}
